﻿/*
*	任务页点击事件
*/

$(document).ready(function () {
    umct_init();
    umct_click_scaleadd();
    umct_click_tag_ingtask();
    umct_click_tag_edtask();
    umct_rtf_takslist_item_change();
    umct_rtf_takslist_item_delete();
    umct_rtf_takslist_item_finsh();
    umct_Enterdown();

});

function umct_init() {
    $('#rtf_edlist_div').hide();
    $('#rtf_inglist_div').show();
}


////数据
var isshow_add_div = true; //是否显示添加任务div
var isshow_moretaskinfo = false; //是否显示更多任务列表的详细信息

////未完成任务Tag标签
function umct_click_tag_ingtask() {
    $("#rtft_tag_ing").click(function (event) {
        is_eddiv = false;
        if (isshow_add_div) {
            $('#rtf_add_div').show();
        }
        $('#rtf_edlist_div').hide();
        $('#rtf_inglist_div').show();

        $('#rtft_tag_ed').css("background-position", "-30px -702px");
        $('#rtft_tag_ed').css("color", "#ccc");

        $('#rtft_tag_ing').css("background-position", "-30px -600px");
        $('#rtft_tag_ing').css("color", "#eee");

        $("#rtft_scaleadd").show();

    });
}

////已完成任务Tag标签
function umct_click_tag_edtask() {
    $("#rtft_tag_ed").click(function (event) {
        is_eddiv = true;
        $('#rtf_add_div').hide();
        $('#rtf_inglist_div').hide();
        $('#rtf_edlist_div').show();

        $('#rtft_tag_ing').css("background-position", "-30px -702px");
        $('#rtft_tag_ing').css("color", "#ccc");

        $('#rtft_tag_ed').css("background-position", "-30px -600px");
        $('#rtft_tag_ed').css("color", "#eee");

        $("#rtft_scaleadd").hide();
    });
}

////显示隐藏添加任务div
function umct_click_scaleadd() {
    $("#rtft_scaleadd").click(function (event) {
        if (isshow_add_div) { //隐藏
            isshow_add_div = false;
            $('#rtf_add_div').hide();
            $('#rtft_scaleadd').css("background-position", "0px -150px");

        } else {
            isshow_add_div = true;
            $('#rtf_add_div').show();
            $('#rtft_scaleadd').css("background-position", "-32px -150px");
        }

    });
}

/// 任务列表item  任务完成
function umct_rtf_takslist_item_finsh() {
    //    var kao = true;
    //    var lastclickid = "id";
    $(".rtf_takslist_item_finsh").die().live("click", function (e) {
        e.preventDefault();
        var thishandle = $(this);
        var taskid = $(this).parent().parent().parent().next().find(".rtfti_id_input").val();
        var content = $(this).parent().parent().next().find(".rtf_takslist_item_content_input").val();
        var date = $(this).parent().parent().parent().next().find(".rtfti_time_input").val();
        var level = $(this).parent().parent().parent().next().find(".rtfti_important_input").val();
        var contact = $(this).parent().parent().parent().next().find(".rtfti_contact_input").val();
        $.ajax({
            url: "/Mange_Main/FinishTask",
            type: "post",
            cache: false,
            data: {
                taskid: taskid
            },
            dataType: "json",
            success: function (msg) {
                if (msg.Result) {

                    //
                    thishandle.css("background-position", "-25px -120px");
                    thishandle.parent().parent().parent().parent().css("opacity", "0");
                    thishandle.parent().parent().parent().parent().delay(400).queue(function () {
                        $(this).remove();
                    });

                    var task_set; //已经完成的任务集合
                    task_set = $("<div class='rtf_takslist_item'>"
                                     + "<!-- 主显示 -->"
                                     + "  <div class='rtf_takslist_item_mainshow'>"
                                     + "      <div class='rtf_takslist_item_content_important'>"
                                     + "         <p class='rtf_takslist_item_content_important_li'></p>"
                                     + "         <p><a class='rtf_edtakslist_item_finsh'></a></p>"
                                     + "      </div>"
                                     + "      <div class='rtf_takslist_item_content_div'>"
                                     + "         <p><input type='text' class='rtf_takslist_item_content_input' name='username'  maxlength='50' placeholder='任务1' value='" + content + "' readOnly='true'  /></p>"
                                     + "         <p><a class='rtf_edtakslist_item_detail'></a></p>"
                                     + "         <p><a class='rtf_takslist_item_delete'></a></p>   "
                                     + "      </div>"
                                     + "  </div>"
                                     + "   <!-- /主显示 -->"
                                     + "  <!-- 任务更多信息 -->"
                                     + "  <div class='rtfti_div'>"
                                     + "      <!-- 时间和联系人 -->"
                                     + "      <ul class='rtfti_ul'>"
                                     + "      <li>时间：<input type='text' class='rtfti_time_input' placeholder='时间' value='" + date + "' readOnly='true' /></li>"
                                     + "      <li>联系人： <input type='text' class='rtfti_contact_input' placeholder='联系人' value='" + contact + "' readOnly='true' /></li>"
                                     + "      </ul>"
                                     + "      <!-- /时间和联系人 -->"
                                     + "      <!-- 重要等级 -->"
                                     + "      <ul class='rtfti_ul'>"
                                     + "      <li>重要：<input type='text' class='rtfti_important_input' placeholder='重要等级' value='" + level + "' readOnly='true' /></li>"
                                     + "      <li>状态：<input type='text' class='rtfti_state_input' placeholder='任务状态' value='完成' readOnly='true'/></li>"
                                     + "      <input type='text' class='rtfti_id_input' placeholder='ID' value='" + taskid + "' readOnly='true' style=' visibility:hidden;' />"
                                     + "      </ul>"
                                     + "     <!-- /重要等级 -->  "
                                     + "  </div>"
                                     + "  <!-- /任务更多信息 -->"
                                     + "</div> ");
                    $("#rtf_edlist_div").prepend(task_set);

                    $(".rtf_takslist_item").die().mouseover(function () {
                        //      $("#left_img_userphoto").css("-webkit-transform", "scale(2.5,2.0)");
                        if ($(this).css("height") == "43px") {
                            $(".rtf_takslist_item").css("height", "43px");
                            $(this).css("height", "115px");
                        }
                    })
                            .mouseout(function () {
                                $(this).css("height", "43px");
                            });

                } else {
                    //                        alert(44);
                    alert("添加失败");
                }
            }
        });
    });

}

/// 按下回车
function umct_Enterdown() {
    $("#rtf_content_input").keydown(function (event) {
        if (event.which == 13) //13等于回车键(Enter)键值,ctrlKey 等于 Ctrl
        {
            var date = $("#rtf_add_detail_addtime").val();
            var contact = $("#rtf_contact").val();
            var level = $("#rtf_add_detail_important").val();

            if (date == "") {
                var d = new Date()
                var vYear = d.getFullYear();
                var vMon = d.getMonth() + 1;
                var vDay = d.getDate();
                var date = vYear + "-" + vMon + "-" + vDay;
                $("#rtf_add_detail_addtime").val(date);
            }

            //            if (contact == "") {

            //                $("#rtf_contact").focus();
            //                return;
            //            }

            //            if (level == "") {
            //                $("#rtf_add_detail_important").focus();
            //                return;
            //            }

            var content = $("#rtf_content_input").val();
            if (content == "") {
                return;
            }
            //
            var reg = new RegExp("(^|&)" + "name" + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象

            var r = window.location.search.substr(1).match(reg); //匹配目标参数
            var email = null;
            if (r != null)
                email = unescape(r[2]);
            $.ajax({
                url: "/Mange_Main/AddTask",
                type: "post",
                cache: false,
                data: {
                    str_task_decript: content,
                    str_task_time: date,
                    str_task_type: level,
                    str_task_state: null,
                    str_task_contact: contact,
                    str_task_email: email
                },
                dataType: "json",
                success: function (msg) {
                    if (msg.Result) {

                        //  动态添加的任务的div
                        var task_set; //已经完成的任务集合
                        task_set = $("<div class='rtf_takslist_item'>"
                                         + "<!-- 主显示 -->"
                                         + "  <div class='rtf_takslist_item_mainshow'>"
                                         + "      <div class='rtf_takslist_item_content_important'>"
                                         + "         <p class='rtf_takslist_item_content_important_li'></p>"
                                         + "         <p><a class='rtf_takslist_item_finsh'></a></p>"
                                         + "      </div>"
                                         + "      <div class='rtf_takslist_item_content_div'>"
                                         + "         <p><input type='text' class='rtf_takslist_item_content_input' name='username'  maxlength='50' placeholder='任务1' value='" + content + "' /></p>"
                                         + "         <p><a class='rtf_takslist_item_detail'></a></p>"
                                         + "         <p><a class='rtf_takslist_item_delete'></a></p>   "
                                         + "      </div>"
                                         + "  </div>"
                                         + "   <!-- /主显示 -->"
                                         + "  <!-- 任务更多信息 -->"
                                         + "  <div class='rtfti_div'>"
                                         + "      <!-- 时间和联系人 -->"
                                         + "      <ul class='rtfti_ul'>"
                                         + "      <li>时间：<input type='text' class='rtfti_time_input' placeholder='时间' value='" + date + "'/></li>"
                                         + "      <li>联系人： <input type='text' class='rtfti_contact_input' placeholder='联系人' value='" + contact + "'/></li>"
                                         + "      </ul>"
                                         + "      <!-- /时间和联系人 -->"
                                         + "      <!-- 重要等级 -->"
                                         + "      <ul class='rtfti_ul'>"
                                         + "      <li>重要：<input type='text' class='rtfti_important_input' placeholder='重要等级' value='" + level + "'/></li>"
                                         + "      <li>状态：<input type='text' class='rtfti_state_input' placeholder='任务状态' value='进行中' readOnly='true'/></li>"
                                         + "      <input type='text' class='rtfti_id_input' placeholder='ID' value='" + msg.Message + "' readOnly='true' style=' visibility:hidden;' />"
                                         + "      </ul>"
                                         + "     <!-- /重要等级 -->  "
                                         + "  </div>"
                                         + "  <!-- /任务更多信息 -->"
                                         + "</div> ");
                        $("#rtf_inglist_div").prepend(task_set);

                        $(".rtf_takslist_item").die().mouseover(function () {
                            //      $("#left_img_userphoto").css("-webkit-transform", "scale(2.5,2.0)");
                            if ($(this).css("height") == "43px") {
                                $(".rtf_takslist_item").css("height", "43px");
                                $(this).css("height", "115px");
                            }
                        })
                                .mouseout(function () {
                                    $(this).css("height", "43px");
                                });

                    } else {
                        //                        alert(44);
                        alert("添加失败");
                    }
                }
            });
        }
    });

}

/// 任务列表item的修改
function umct_rtf_takslist_item_change() {
    $(".rtf_takslist_item_detail").die().live("click", function (e) {
        e.preventDefault();
//        alert($(this).parent().parent().parent().next().find(".rtfti_id_input").val());
//        var thishandle = $(this);

        var taskid = $(this).parent().parent().parent().next().find(".rtfti_id_input").val();


        var content = $(this).parent().parent().find(".rtf_takslist_item_content_input").val();
        var date = $(this).parent().parent().parent().next().find(".rtfti_time_input").val();
        var level = $(this).parent().parent().parent().next().find(".rtfti_important_input").val();
        var contact = $(this).parent().parent().parent().next().find(".rtfti_contact_input").val();

        $.ajax({
            url: "/Mange_Main/ChangeTask",
            type: "post",
            cache: false,
            data: {
                taskid: taskid,
                str_task_decript: content,
                str_task_time: date,
                str_task_type: level,
                str_task_contact: contact
            },
            dataType: "json",
            success: function (msg) {
                if (msg.Result) {
                    alert("修改成功");

                } else {
                    alert("修改失败");
                }
            }
        });
    });

}

/// 删除
function umct_rtf_takslist_item_delete() {
    $(".rtf_takslist_item_delete").die().live("click", function (e) {
        e.preventDefault();
        var thishandle = $(this);
        var taskid = $(this).parent().parent().parent().next().find(".rtfti_id_input").val();
        $.ajax({
            url: "/Mange_Main/DeleteTask",
            type: "post",
            cache: false,
            data: {
                taskid: taskid
            },
            dataType: "json",
            success: function (msg) {
                if (msg.Result) {

                    thishandle.css("background-position", "-25px -120px");
                    thishandle.parent().parent().parent().parent().css("opacity", "0");
                    thishandle.parent().parent().parent().parent().delay(400).queue(function () {
                        $(this).remove();
                    });

                } else {
                    alert("删除失败");
                }
            }
        });
    });

}
 